package com.example.administrator.maizuofilm.moviedetails.moviedetailsadapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.BitmapImageViewTarget;
import com.example.administrator.maizuofilm.R;
import com.example.administrator.maizuofilm.moviedetails.bean.Details;

import java.util.List;

/**
 * Created by hansen on 2016/7/13.
 */
public class MovieDetailsAdapter extends RecyclerView.Adapter<MovieDetailsAdapter.viewHold> {
    private List<Details.DataBean.ActorInfoBean> details;
   private viewHold hold;
    private Context context;
    public MovieDetailsAdapter(List<Details.DataBean.ActorInfoBean> details, Context context){
        this.details=details;
        this.context=context;
    }

    @Override
    public viewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.moviedetails_actor,null);

             hold=new viewHold(view);


        return hold;
    }

    @Override
    public void onBindViewHolder(final viewHold holder, int position) {
//       int size= details.getData().get(0).getActorInfo().size();
        holder.moviedetails_actorName.setText(details.get(position).getActorName());
        holder.moviedetails_name.setText(details.get(position).getActorRole());
        String picPath=details.get(position).getPath();
      //  Glide.with(context).load(picPath).into(holder.moviedetails_actorPic);
        Glide.with(context).load(picPath).asBitmap().centerCrop().into(new BitmapImageViewTarget(holder.moviedetails_actorPic) {
            @Override
            protected void setResource(Bitmap resource) {
                RoundedBitmapDrawable circularBitmapDrawable =
                        RoundedBitmapDrawableFactory.create(context.getResources(), resource);
                circularBitmapDrawable.setCircular(true);
                holder.moviedetails_actorPic.setImageDrawable(circularBitmapDrawable);
            }
        });
    }

    @Override
    public int getItemCount() {
        return details.size();
    }

    class viewHold extends RecyclerView.ViewHolder {
        ImageView moviedetails_actorPic;
        TextView moviedetails_actorName,moviedetails_name;

        public viewHold(View itemView) {
            super(itemView);
            moviedetails_actorPic= (ImageView) itemView.findViewById(R.id.moviedetails_actorPic);
            moviedetails_actorName= (TextView) itemView.findViewById(R.id.moviedetails_actorName);
            moviedetails_name= (TextView) itemView.findViewById(R.id.moviedetails_name);
        }
    }
}
